package com.nanyang.tms.controller.dataimport;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.dataimport.DataImportRequest;
import com.nanyang.tms.api.dto.request.dataimport.DataImportResultLineQueryRequest;
import com.nanyang.tms.api.dto.request.dataimport.DataImportResultQueryRequest;
import com.nanyang.tms.api.dto.response.dataimport.DataImportResultLineResponse;
import com.nanyang.tms.api.dto.response.dataimport.DataImportResultResponse;
import com.nanyang.tms.api.service.dataimport.DataImportRpcService;

@RestController
@RequestMapping("/import")
public class DataImportController {
	 @Reference(version = "1.0.0", timeout = 10000, check = false)
	 private DataImportRpcService dataImportRpcService;
	 @BindParam
	 @RequestMapping(value = "/add", method = RequestMethod.POST)
	 public ApiResult<Boolean> importData(@Valid @RequestBody @BindParam DataImportRequest dataImportRequest){
		
		 ApiResult<Boolean> apiResult = dataImportRpcService.saveImportFile(dataImportRequest);
		 if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
	            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
	        }
	       return apiResult;
		  
	  }
	 
	 @BindParam
	 @RequestMapping(value = "/list", method = RequestMethod.POST)
	 public ApiResult<PageBean<DataImportResultResponse>> listDataImport(@Valid @RequestBody @BindParam DataImportResultQueryRequest dataImportResultQueryRequest){
		
		 ApiResult<PageBean<DataImportResultResponse>> apiResult = dataImportRpcService.listDataImportResult(dataImportResultQueryRequest);
		 if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
	            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
	        }
	       return apiResult;
		  
	  }
	 @BindParam
	 @RequestMapping(value = "/result", method = RequestMethod.POST)
	 public ApiResult<PageBean<DataImportResultLineResponse>> listDataImportLine(@Valid @RequestBody @BindParam DataImportResultLineQueryRequest dataImportResultLineQueryRequest){
		
		 ApiResult<PageBean<DataImportResultLineResponse>> apiResult = dataImportRpcService.listDataImportResultLine(dataImportResultLineQueryRequest);
		 if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
	            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
	        }
	       return apiResult;
		  
	  }
}
